<template>
  <div class="pl-nm pr-nm pt-nm">
    <Loading
      v-if="loadingShow"
      :loadingShow="loadingShow"
      type="fix"
    ></Loading>
    <TsTable
      v-else
      v-bind="tableConfig"
      :theadList="theadList"
      @changeCurrent="changeCurrent"
      @changePageSize="changePageSize"
    >
      <template slot="" slot-scope="{row}">
        {{ row }}
      </template>
    </TsTable>
  </div>
</template>
<script>
export default {
  name: '',
  components: {
    TsTable: resolve => require(['@/resources/components/TsTable/TsTable.vue'], resolve)
  },
  props: {
    versionId: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      loadingShow: true,
      tableConfig: {
        currentPage: 1,
        pageSize: 20,
        tbodyList: []
      },
      theadList: [
        {
          title: 'Dependency',
          key: 'dependency'
        },
        {
          title: 'Vulnerability IDs',
          key: 'vulnerabilityIds'
        },
        {
          title: 'Package',
          key: 'packageName'
        },
        {
          title: 'HighestSeverity',
          key: 'highestSeverity'
        },
        {
          title: 'CVE Count',
          key: 'cveCount'
        },
        {
          title: 'Confidence',
          key: 'confidence'
        },
        {
          title: 'Evidence Count',
          key: 'evidenceCount'
        }
      ]
    };
  },
  beforeCreate() {},
  created() {
    this.searchCevData();
  },
  beforeMount() {},
  mounted() {},
  beforeUpdate() {},
  updated() {},
  activated() {},
  deactivated() {},
  beforeDestroy() {},
  destroyed() {},
  methods: {
    changeCurrent(currentPage) {
      this.tableConfig.currentPage = currentPage;
      this.searchCevData();
    },
    changePageSize(pageSize) {
      this.tableConfig.currentPage = 1;
      this.tableConfig.pageSize = pageSize;
      this.searchCevData();
    },
    searchCevData() {
      let params = {
        versionId: this.versionId,
        currentPage: this.tableConfig.currentPage,
        pageSize: this.tableConfig.pageSize
      };
      if (!this.versionId) {
        this.loadingShow = false;
        this.$emit('hideTab', false);
        return false;
      }
      this.loadingShow = true;
      this.$api.deploy.version.getCveloopholeList(params).then(res => {
        if (res.Status == 'OK') {
          Object.assign(this.tableConfig, res.Return);
          this.$emit('hideTab', !this.$utils.isEmpty(this.tableConfig.tbodyList)); // 提供给外部使用，无数据时，不显示整个tab
        }
      }).finally(() => {
        this.loadingShow = false;
      });
    }
  },
  filter: {},
  computed: {},
  watch: {}
};
</script>
<style lang="less">
</style>
